#!/usr/bin/env bash

if (( $# != 1 )); then
    printf 'Usage: %s path/to/public_html\n' "$(basename "$0")"
    exit 1
fi

DIR="$1"

if [ ! -d "$DIR" ]; then
    printf '%s is not a directory!' "$DIR"
    exit 1
fi

# Standardize format for $DIR
DIR=$( cd "$DIR" && pwd )

eval "$("$HOME"/.amazonrc)"
s3cmd put --recursive "${DIR}/" "s3://photos.tylercipriani.com/"

for file in "${DIR}"/*; do
    fn=$(basename "$file")
    s3cmd setacl --acl-public  --recursive "s3://photos.tylercipriani.com/${fn}"
done

s3cmd modify --add-header='Content-type:text/css'  --recursive "s3://photos.tylercipriani.com/main.css"
